/*
题目链接 : https://leetcode.cn/problems/unique-3-digit-even-numbers/description/
*/

//题解代码:
class Solution {
public:
    set<int> s;
    int totalNumbers(vector<int>& digits) {
        int n = digits.size();
        vector<int> path;
        auto dfs2 = [&](auto&& dfs2,vector<int>& path,int i)->void{
            if(i==3){
                int cur = path[0]*100 + path[1] *10 + path[2];
                if(cur%2 == 0 && path[0]) s.insert(cur);
                return;
            }
            for(int j=i;j<3;++j){
                swap(path[i],path[j]);
                dfs2(dfs2,path,i+1);
                swap(path[i],path[j]);
            }
        };
        auto dfs = [&](auto&& dfs,int i,vector<int>& path)->void{
            if(path.size()==3){
                dfs2(dfs2,path,0);
                return;
            }
            if(i>=n) return;
            path.push_back(digits[i]);
            dfs(dfs,i+1,path);
            path.pop_back();
            dfs(dfs,i+1,path);
        };
        dfs(dfs,0,path);
        return s.size();
    }
};
